package com.zwb.aiwebsite.service.impl;

import com.zwb.aiwebsite.entity.TbCarousel;
import com.zwb.aiwebsite.mapper.TbCarouselMapper;
import com.zwb.aiwebsite.repository.TbCarouselRepository;
import com.zwb.aiwebsite.service.TbCarouselService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 2825075112@qq.com
 * @since 2021-05-07
 */
@Service
public class TbCarouselServiceImpl implements TbCarouselService {

    @Resource
    private TbCarouselRepository tbCarouselRepository;
    @Resource
    private TbCarouselMapper tbCarouselMapper;


    @Override
    public void add(TbCarousel tbCarousel) {
        if (StringUtils.isBlank(tbCarousel.getImgUrl())) {
            return;
        }
        if (tbCarousel.getOrder() == null) {
            tbCarousel.setOrder(1);
        }
        tbCarouselRepository.save(tbCarousel);
    }

    @Override
    public List<TbCarousel> all() {
        return tbCarouselRepository.findAll();
    }

    @Override
    public void del(Integer id) {
        tbCarouselRepository.deleteById(id);
    }
}
